home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7883 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  76 lines

  1. Newsgroups: comp.lang.c++
  2. Path: esds01.es.dupont.com!news
  3. From: Malcolm Smart <MALCOLM.SMART@CONOCO.DUPONT.COM>
  4. Subject: ***NASA USE C++ TO GO MARTIAN ***
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <1996Feb15.100604.29166@es.dupont.com>
  7. Sender: news@es.dupont.com (USENET News System)
  8. Nntp-Posting-Host: slai99.wrk.dupont.com
  9. Content-Transfer-Encoding: 7bit
  10. Organization: Conoco/DuPont
  11. References: <1996Feb13.095916.26002@es.dupont.com>
  12. Mime-Version: 1.0
  13. Date: Thu, 15 Feb 1996 10:06:04 GMT
  14. X-Mailer: Mozilla 1.1 (Windows; I; 16bit)
  15.  
  16. (Sorry about the title, but nobody answered (or even read it!) under 
  17. the boring title of "Help with Containers")
  18.  
  19. Hi
  20.  
  21. I want to modify a class which has been stored in a direct container.  
  22. I'm not sure if this is only relative to Borland compilers as that is all 
  23. I have used.  A simplified section of code is shown below explaining what 
  24. I am doing, and also what I want :-
  25.  
  26. class TMyClass
  27.    {
  28.    overloaded == , = , < operators;  (all work)
  29.    TMyClass() {};
  30.    copy constructor (works)
  31.    //
  32.    char Member[255];
  33.    };
  34.  
  35. typedef TArrayAsVector<TMyClass> ArrayOfMyClasses;
  36.  
  37.  
  38.  
  39. int main(var1 , var2)  //not sure what they are
  40.    {
  41.    ArrayOfMyClasses MyArray(5,0,5);      //create array
  42.    TMyClass c();                 //instance of TMyClass    
  43.    MyArray.Add(c);            //Add instance to container
  44.    TMyClass d();            //Another instance
  45.    MyArray.Add(d);            //Add this instance to container.
  46.     
  47.   //using an ArrayIterator or ForEach, I can access the data no problem. 
  48.   // I want to access/change the data using [].
  49.  
  50.    strcpy((TMyClass&)MyArray[0].Member ,  "Some String");  //DOES NOT 
  51. WORK!
  52.  
  53.    };
  54.  
  55.  
  56. The above code is not perfect by a long way but it should explain what I 
  57. am trying to do. The contents of (TMyClass&)MyArray[0] are 
  58. random/corrupt.  Without the caster (TMyClass&) the compiler comes back 
  59. with "Member is not a member of TArrayAsVector<TMyClass>"
  60.  
  61. Any ideas?
  62.  
  63. Thanks in advance
  64.  
  65. >--Malc.
  66. >
  67. >The above questions are mine and not those of my employer.
  68. >  
  69. >
  70. >
  71. >
  72. >   
  73. >
  74.  
  75.  
  76.